#if !SILVERLIGHT
#region COPYRIGHT
//--------------------------------------------------------------------------------
// <copyright file="InputCameraController.cs" company="starLiGHT Entertainment Studios">
//    Copyright (c) 2007, 2008, 2009, 2010
//       Roland Rosenkranz (Glatzemann@email.de)
// </copyright>
// <license>
//   This file is part of starLiGHT.Render.
//
//   starLiGHT.Render is free software: you can redistribute it and/or modify
//   it under the terms of the GNU Lesser General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   starLiGHT.Core is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU Lesser General Public License for more details.
//
//   You should have received a copy of the GNU Lesser General Public License
//   along with starLiGHT.Render. If not, see http://www.gnu.org/licenses/.
//    
//   ADDITIONAL (commercial) LICENSES for starLiGHT.Render are available on request.
// </license>
// <version>
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev:: 620                   $:  Revision of last commit *
// * $Author:: unknown            $:  Author of last commit   *
// * $Date:: 2010-12-07 15:23:58 #$:  Date of last commit     *
// ************************************************************
// </version>
//--------------------------------------------------------------------------------
#endregion

namespace starLiGHT.Camera.TwoD
{
    #region Using Statements
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Input;
    using starLiGHT.Input;

    #endregion

    public class InputCameraController : ICameraController
    {
        private InputManager inputManager;
        private float translationSpeed = 1.0f;
        private float zoomSpeed = 0.01f;
        private float rotationSpeed = 0.01f;

        public InputCameraController(InputManager inputManager, bool defaultMapping)
        {
            this.inputManager = inputManager;
            if (defaultMapping)
            {
                this.RegisterDefaultMapping();
            }
        }

        public InputCameraController(Microsoft.Xna.Framework.Game game, bool defaultMapping)
        {
            this.inputManager = new InputManager(game);
            game.Components.Add(this.inputManager);

            if (defaultMapping)
            {
                this.RegisterDefaultMapping();
            }
        }

        public string Name
        {
            get { return "Input"; }
        }

        public InputManager InputManager
        {
            get { return this.inputManager; }
            set { this.inputManager = value; }
        }

        public void Update(GameTime gameTime, Camera2D camera)
        {
            Vector2 translation = new Vector2();

            if (this.inputManager.IsActionHeld("LEFT"))
            {
                translation.X += this.translationSpeed;
            }

            if (this.inputManager.IsActionHeld("RIGHT"))
            {
                translation.X -= this.translationSpeed;
            }

            if (this.inputManager.IsActionHeld("UP"))
            {
                translation.Y += this.translationSpeed;
            }

            if (this.inputManager.IsActionHeld("DOWN"))
            {
                translation.Y -= this.translationSpeed;
            }

            camera.Anchor += translation;

            if (this.inputManager.IsActionHeld("ZOOMIN"))
            {
                camera.Zoom += this.zoomSpeed;
            }

            if (this.inputManager.IsActionHeld("ZOOMOUT"))
            {
                camera.Zoom -= this.zoomSpeed;
            }

            if (this.inputManager.IsActionHeld("ROTATELEFT"))
            {
                camera.Rotation -= this.rotationSpeed;
            }

            if (this.inputManager.IsActionHeld("ROTATERIGHT"))
            {
                camera.Rotation += this.rotationSpeed;
            }
        }

        private void RegisterDefaultMapping()
        {
            //////////TODO: restore default mappings

            ////inputManager.addAction("LEFT", new ControlSchemeButton(true, Buttons.DPadLeft, Keys.Left));
            ////inputManager.addAction("LEFT", new ControlSchemeButton(true, Keys.A));
            ////inputManager.addAction("RIGHT", new ControlSchemeButton(true, Buttons.DPadRight, Keys.Right));
            ////inputManager.addAction("RIGHT", new ControlSchemeButton(true, Keys.D));
            ////inputManager.addAction("UP", new ControlSchemeButton(true, Buttons.DPadUp, Keys.Up));
            ////inputManager.addAction("UP", new ControlSchemeButton(true, Keys.W));
            ////inputManager.addAction("DOWN", new ControlSchemeButton(true, Buttons.DPadDown, Keys.Down));
            ////inputManager.addAction("DOWN", new ControlSchemeButton(true, Keys.S));

            ////inputManager.addAction("ZOOMIN", new ControlSchemeButton(true, Buttons.RightShoulder, Keys.OemPlus));
            ////inputManager.addAction("ZOOMOUT", new ControlSchemeButton(true, Buttons.LeftShoulder, Keys.OemMinus));

            ////inputManager.addAction("ROTATELEFT", new ControlSchemeButton(true, Keys.Q));
            ////inputManager.addAction("ROTATERIGHT", new ControlSchemeButton(true, Keys.E));
        }
    }
}
#endif
